<template>
    <div class="movePopout">
        <!--背景-->
        <div class="popout-bg" @mousemove="mousemove">
            <div
                class="popout-main"
                v-bind:class="{'isMax':isMax == 2,'isMin':isMax == 0}"
                v-bind:style="getPosition(height)"
            >
                <div class="title" @mousedown="mousedown" @mouseup="mouseup">
                    <div class="text" v-if="isMax !== 0">
                        <div class="txt"><span>{{title || '提示'}}</span></div>
                        <div class="cssborder"></div>
                        <div class="cssborder2"></div>
                        <div class="cssborder3"></div>
                    </div>
                    <div v-else style="padding-left: 15px;">
                        {{title || '提示'}}
                    </div>
                    <div class="tool" @mousedown.stop>
                        <!--最小化-->
                        <i class="el-icon-minus" v-show="isMax == 1" @click="setIsMax(0)"></i>
                        <!--最大化-->
                        <i class="el-icon-top-right" @click="setIsMax(2)" v-show="isMax == 1" v-if="!isShowMax"></i>
                        <!--正常化-->
                        <i class="el-icon-copy-document" @click="setIsMax(1)" v-show="isMax != 1"></i>
                        <!--关闭-->
                        <i class="el-icon-close" @click="close()"></i>
                    </div>
                </div>
                <div class="content" v-show="isMax != 0" :class="isBottom ? '': 'no'">
                    <slot name="content"></slot>
                </div>
                <div class="bottom" :class="isBottom ? '': 'no'">
                    <div class="contain">
                        <slot name="bottom"></slot>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
export default {
    name: "movePopout",
    props: {
        title: {
            default: function() {
                return '';
            },
            type: String
        },
        visible: {
            default: function() {
                return false;
            },
            type: Boolean
        },
        height: {
            default: function() {
                return '';
            },
            type: String
        },
        isBottom: {
            default: function() {
                return true;
            },
            type: Boolean
        },
        isMove: {
            default: function() {
                return true;
            },
            type: Boolean
        },
        isShowMax: {
            default: function() {
                return false;
            },
            type: Boolean
        }
    },
    data() {
        return {
            isMax: 1, //是否是最大化 0 最小 1 正常  2最大
            left: false, //弹框left距离 false 代表初始移动位置
            top: false, //弹框top距离 false 代表初始移动位置
        };
    },
    watch: { },
    methods: {
        confirm() {
            //确定
            this.$emit("update:visible", true);
        },
        close() {
            //关闭
            this.$emit("update:visible", false);
        },
        setIsMax(val) {
            //设置窗口最大化、最小化
            this.left = false; //位置初始化
            this.top = false; //位置初始化
            this.isMax = val;
        },
        mousedown(e) {
            if(this.isMove) {
                //按下
                this.down = true; //添加监听
                this.titleX = e.offsetX; //添加监听
                this.titleY = e.offsetY; //添加监听
            }
        },
        mousemove(e) {
            //移动
            if (this.down) {
                let x = e.clientX,
                    y = e.clientY;
                this.left = x - this.titleX; //设置弹框移动
                this.top = y - this.titleY; //设置弹框移动
            }
        },
        mouseup(e) {
            if(this.isMove) {
                //松开
                this.down = false; //不添加监听
            }
        },
        getPosition(height) {
            //返回弹框位置
            if (this.left === false || this.top == false) {
                return {
                    height: height,
                };
            } else {
                return {
                    left: this.left + "px",
                    top: this.top + "px",
                    height: height,
                };
            }
        },
    },
    mounted() {

    },
    components: {},
};
</script>
<style scoped lang="scss">
.movePopout {
    /*弹框背景*/
    .popout-bg {
        position: absolute;
        overflow: hidden;
        width: 100%;
        height: 100%;
        left: 0;
        top: 0;
        z-index: 9;
        background: rgba(0, 0, 0, 0.4);
    }
    /*弹框内容*/
    .popout-main {
        &.isMax {
            width: calc(100% - 60px);
            height: calc(100% - 60px) !important;
            left: 30px;
            top: 30px;
        }
        &.isMin {
            width: 200px;
            height: 40px !important;
            left: 0;
            bottom: -1px;
            overflow: hidden;
            top: auto;
        }
        position: absolute;
        width: 600px;
        height: 460px;
        top: calc(50% - 230px);
        background: #ffffff;
        z-index: 10;
        left: calc(50% - 300px);
        overflow: hidden;
        font-size: 12px;
        /*标题*/

        .title {
            height: 45px;
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: space-between;
            color: #ffffff;
            background: #284358;
            cursor: move;
            .text {
                font-weight: normal;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
                flex: 1;
                text-align: center;
                font-size: 14px;
                .txt {
                    line-height: 35px;
                    height: 35px;
                    position: relative;
                    display: flex;
                    flex-wrap: nowrap;
                    align-content: center;
                    justify-content: center;
                    span {
                        position: absolute;
                        top: 5px;
                    }
                }
                .cssborder {
                    background: #ffffff;
                    position: relative;
                    height: 10px;
                    line-height: 10px;
                    width: 28%;
                    float: left;
                    z-index: 1111;
                    &::after {
                        content: '';
                        width: 0;
                        height: 0;
                        border-bottom: 10px solid transparent;
                        border-right: 15px solid #284358;
                        position: absolute;
                        right: 0;
                        top: 0;
                    }
                }
                .cssborder2 {
                    background: #284358;
                    position: relative;
                    height: 10px;
                    line-height: 10px;
                    width: 44%;
                    float: left;
                    z-index: 1111;
                }
                .cssborder3 {
                    background: #ffffff;
                    position: relative;
                    height: 10px;
                    line-height: 10px;
                    width: 28%;
                    float: left;
                    z-index: 1111;
                    &::after {
                        content: '';
                        width: 0;
                        height: 0;
                        border-bottom: 10px solid transparent;
                        border-left: 15px solid #284358;
                        position: absolute;
                        left: 0;
                        top: 0;
                    }
                }
            }
            .tool {
                max-width: 120px;
                text-align: right;
                padding-right: 20px;
                height: 100%;
                line-height: 30px;
                cursor: initial;
                position: absolute;
                right: 0;
                top: 2px;
                i {
                    cursor: pointer;
                    font-size: 16px;
                    font-weight: bold;
                    margin-left: 10px;
                    &:hover {
                        opacity: 0.7;
                    }
                }
            }
        }
        /*内容*/
        .content {
            height: calc(100% - 95px);
            display: block;
            flex-direction: column;
            position: relative;
            overflow: auto;
            padding: 50px 50px 0px 50px;
            position: relative;
            &.no {
                height: calc(100% - 40px);
            }
        }
        /*底部按钮*/
        .bottom {
            height: 45px;
            width: 100%;
            .contain {
                height: 30px;
                margin: 10px auto;
                border-spacing: 30px 0;
                display: table;
                .zll-botton {
                    margin: 0 20px;
                    display: table-cell;
                    vertical-align: middle;
                }
            }
            &.no {
                display: none;height: 0;
            }
            .confirm,
            .clear {
                height: 35px;
                line-height: 35px;
                padding: 0 20px;
                border: 1px solid #409eff;
                color: #409eff;
                background: #ffffff;
                cursor: pointer;
                // border-radius: 2px;
                i {
                    font-weight: bold;
                }
                &:hover {
                    color: #5789d7;
                    border-color: #5789d7;
                    background: rgba(0, 0, 0, 0.03);
                }
            }
            .clear {
                margin-left: 10px;
            }
        }
    }
}
.bigSize {
    .popout-main {
        width: 800px;
        left: calc(50% - 400px);
    }
}
.largeSize {
    .popout-main {
        width: 1000px;
        left: calc(50% - 500px);
    }
}
.bg_Size {
    .popout-main {
        width: 1000px;
        left: calc(50% - 500px);
        height: 600px;
        top: calc(50% - 300px);
        .content {
            padding: 20px 80px 0px 80px;
        }
    }
}
.bg_maxSize {
	.popout-main {
		width: 1300px;
		left: calc(50% - 650px);
		height: 600px;
		top: calc(50% - 300px);
		.content {
			padding: 20px 80px 0px 80px;
		}
	}
}
.max_size {
    .popout-main {
        width: 1300px;
        left: calc(50% - 650px);
        height: 600px;
        top: calc(50% - 300px);
        .content {
            padding: 20px 80px 0px 80px;
        }
    }
}

.minhSize {
	.popout-main {
		font-size: 12px;
		width: 400px;
		height: 200px;
		left: calc(50% - 200px);
		top: calc(50% - 250px);
	}
}

.minSize {
    .popout-main {
        font-size: 12px;
        width: 400px;
        height: 350px;
        left: calc(50% - 200px);
        top: calc(50% - 250px);
    }
}
.long_size {
    .popout-main {
        font-size: 12px;
        width: 600px;
        height: 350px;
        left: calc(50% - 300px);
        top: calc(50% - 250px);
    }
}
.changePassword {
    .movePopout .popout-bg {
        position: fixed;
    }
}
.userEdit {
    .popout-main {
        height: 500px;
    }
}
.hr {
    .popout-main {
        height: 500px;
        width: 800px;
        left: calc(50% - 400px);
    }
}
.orderSize {
    .popout-main {
        width: 1200px;
        left: calc(50% - 600px);
    }
}
.agv {
    .popout-main {
        width: 800px;
        height: 300px;
        left: calc(50% - 400px);
    }
}
</style>
